package com.tanhua.manage.controller;


import com.tanhua.manage.service.CommentPageService;
import com.tanhua.manage.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("management/manage/messages")
public class CommentPageController {

    @Autowired
    private CommentPageService commentPageService;

    @GetMapping("comments")
    public ResponseEntity<PageResult> queryCommentList(
            @RequestParam("pagesize")String pageSize,   //页尺寸
            @RequestParam("page")String page,   //当前页码
            @RequestParam("sortProp")String sortProp,  //排序字段
            @RequestParam("sortOrder")String sortOrder,  //ascending升序,descending降序
            @RequestParam("messageID")String messageId    //消息Id
    ){
        try {
            PageResult pageResult = this.commentPageService.queryCommentList(page, pageSize, sortProp, sortOrder, messageId);
            if (null!=pageResult){
                return ResponseEntity.ok(pageResult);
            }
        }catch (Exception e){
            log.error("消息翻页失败");
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
